<!doctype html>
<html lang="en">

<head>
	<meta charset="utf-8"/>
	<title>Dashboard I Admin Panel</title>
	
	<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
	<!--[if lt IE 9]>
	<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
	<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
	<script src="js/hideshow.js" type="text/javascript"></script>
	<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/jquery.equalHeight.js"></script>
	
	<script type="text/javascript">
	$(document).ready(function() { 
      	  $(".tablesorter").tablesorter();
   	 });

	$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});
    </script>
    
	<script type="text/javascript">
    $(function(){
        $('.column').equalHeight();
    });
   </script>

	<script>
		$(document).ready(function(){
		$('#new_user_section').hide();
			 $('#newuser').click(function(){
				$('#main').hide();
				$('#new_user_section').show();
			});
			
			$('#newarticle').click(function(){
				$('#main').show();
				$('#new_user_section').hide();
			});
			
		});
	</script>

	<script>
		function deleteRow(id){

			var conf_val = confirm("Do u really want to delete this SubLocation ?");
			if(conf_val == true){
				window.location="commonController/DeleteSubLocationController.php?id="+id;
			}
			
		}
	</script>
	<script>
		function editRow(id){
			var sublocationId = document.getElementById("sublocation"+id);
			var sublocationName = sublocationId.textContent;
			var masterLocationId = document.getElementById("masterlocation"+id);
			var masterLocationName = masterLocationId.textContent;
			
			document.getElementById("sublocation").value = sublocationName;
			document.getElementById("sublocationId").value = sublocationId.parentNode.id;
		
			
			var location_dd = document.getElementById("location_dd");
			 for ( var i = 0; i < location_dd.options.length; i++ ) {
				var locationName = location_dd.options[i].text;				
				if (locationName.trim() == masterLocationName.trim()) {
					location_dd.options[i].selected = true;	
					break;
				}
			 }
		}
	</script>

</head>


<body>

	<section id="main" class="column">
		
		<h4 class="alert_info">Welcome to the Admin panel of SubLocation</h4>
		
		<article class="module width_3_quarter">
		<header><h3 class="tabs_involved">SubLocation Manager</h3>
		<ul class="tabs">
   			<li><a href="#tab1">Posts</a></li>
    		<li><a href="#tab2">Comments</a></li>
		</ul>
		</header>

		<div class="tab_container">
			<div id="tab1" class="tab_content" style="height:280px;overflow:auto;">
					<table class="tablesorter" cellspacing="0"> 
			<thead> 
				<tr> 
   					<th>SubLocation Name</th> 
					<th>Location Name</th>
					<th>Created Date</th>
					<th>Action</th> 
				</tr> 
			</thead> 
			<tbody> 
			<?php 
				 //Connects to your Database 
				 $db_host = 'localhost';
				 $db_user = 'function';
				 $db_pwd = 'w9ak4X1l0Y';

				 $database = 'function_a5110060';

				 $con = mysql_connect($db_host, $db_user, $db_pwd); 
				 mysql_select_db($database,$con) or die(mysql_error()); 
				 $data = mysql_query("SELECT sm.sub_location_id, sm.master_location_id, lm.master_location_name, sm.sub_location_name,sm.created_date FROM Location_Master lm, Sub_Location_Master sm WHERE lm.master_location_id = sm.master_location_id") or die(mysql_error()); 
				 while($info = mysql_fetch_array( $data )) 
				 { 
					 Print "<tr id=".$info['sub_location_id'].">";
					 Print	"<td id=sublocation".$info['sub_location_id'].">".$info['sub_location_name']."</td>"; 
					 Print	"<td id=masterlocation".$info['sub_location_id'].">".$info['master_location_name']." </td>";					
					 Print	"<td>".$info['created_date']."</td>";
					 Print	"<td><a href='#' onclick='editRow(this.id)'  id=".$info['sub_location_id']."><input type='image' src='images/icn_edit.png' title='Edit'></a><a href='#' onclick='deleteRow(this.id)'  id=".$info['sub_location_id']."><input type='image' src='images/icn_trash.png' title='Trash'></a></td>";
					 Print "</tr>";
				 } 
			?> 
			</tbody> 
			</table>
			</table>
			</div><!-- end of #tab2 -->
			
		</div><!-- end of .tab_container -->
		
		</article><!-- end of content manager article -->
		
		<article class="module width_quarter">
			<header><h3>Registered Contacts</h3></header>
			<div class="message_list">
				<div class="module_content">
					<div class="message"><p><input type="checkbox">Kameshwara Pavan Kumar Mantha</p>
					<p><strong>9949493991</strong></p></div>
					<div class="message"><p><input type="checkbox">Krishna Pandu Ranga Malladi</p>
					<p><strong>9491884908</strong></p></div>
					<div class="message"><p><input type="checkbox">Raju</p>
					<p><strong>1234567890</strong></p></div>
					<div class="message"><p><input type="checkbox">Vishal</p>
					<p><strong>1234567890</strong></p></div>
					<div class="message"><p><input type="checkbox">Keshav</p>
					<p><strong>1234567890</strong></p></div>
				</div>
			</div>
			<footer>
				<form class="post_message">
					<input type="text" value="Message" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
					<input type="submit" class="btn_post_message" value=""/>
				</form>
			</footer>
		</article><!-- end of messages article -->
		
		<div class="clear"></div>
		
		<form method="" action="commonController/AddSubLocationController.php">
		<article class="module width_full">
				<header><h3>Add or Update Sub Location</h3></header>
				<div class="module_content">
						<fieldset>
							<label>Sub Location Name</label>
							<input type="text" name="sublocation" id="sublocation">
							<input type="text" name="sublocationId" id="sublocationId" style="display: none;"/>
						</fieldset>
						<fieldset style="width:48%; float:left; margin-right: 3%;"> <!-- to make two field float next to one another, adjust values accordingly -->
							<label>Location</label>
							<select style="width:92%;" name="location_dd" id="location_dd">
							<?php 
								 //Connects to your Database 
								 $db_host = 'localhost';
								 $db_user = 'function';
								 $db_pwd = 'w9ak4X1l0Y';

								 $database = 'function_a5110060';

								 $con = mysql_connect($db_host, $db_user, $db_pwd); 
								 mysql_select_db($database,$con) or die(mysql_error()); 
								 $data = mysql_query("SELECT master_location_id,master_location_name FROM Location_Master") 
								 or die(mysql_error()); 
								 while($info = mysql_fetch_array( $data )) 
								 { 									
									 Print	"<option value='".$info['master_location_id']."'>".$info['master_location_name']."</option>";   
								 } 
							?> 
								
							</select>
						</fieldset><div class="clear"></div>
				</div>
			<footer>
				<div class="submit_link">
					
					<input type="submit" value="Add or Update SubLocation" class="alt_btn">
					<input type="submit" value="Reset">
				</div>
			</footer>
		</article><!-- end of post new article -->
		</form>

		<div class="spacer"></div>
	</section>
	


</body>

</html>